package com.example.timecodecalc;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class LayoutButton extends Button implements OnLongClickListener {
	LayoutParams lp;
	int lbstyle;
	
	public LayoutButton(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		super.setWidth(super.getWidth()*2);
	}

	@Override
	public boolean onLongClick(View v) {
		// TODO Auto-generated method stub
		
		return false;
	}
	public Button AddButton(Object o) {
		// TODO Auto-generated method stub
		LayoutButton LButton;
		lbstyle=(o instanceof LinearLayout)?R.drawable.layout:
			(o instanceof FrameLayout)?R.drawable.framelayout:
			(o instanceof RelativeLayout)?R.drawable.relativelayout:R.drawable.simple;
		ContextThemeWrapper newContext = new ContextThemeWrapper(((View)o).getContext(), lbstyle);
		if(checkchild(o))
		{
			LButton=new LayoutButton(((View)o).getContext());
			return LButton;
		} 
		else return null;
	}
private boolean checkchild(Object o){
	
	int countchild = 
			(o instanceof LinearLayout)?((LinearLayout)o).getChildCount():
			(o instanceof FrameLayout)?((FrameLayout)o).getChildCount():
			(o instanceof RelativeLayout)?((RelativeLayout)o).getChildCount():99999;
	
			return 	(o instanceof LinearLayout)?true:(o instanceof FrameLayout)?true:(o instanceof RelativeLayout)?true:false & (countchild==0)  ;
									}
}
